﻿using System.Windows.Forms;

namespace SuperStarRounds.Classes.Utility
{
  public static class FormUtility
  {
    public static void OnEntrySelectAllText(object sender)
    {
      var textBox = sender as TextBox;
      if (textBox != null)
      {
        textBox.SelectAll();
        return;
      }

      var comboBox = sender as ComboBox;
      if (comboBox != null)
      {
        comboBox.SelectAll();
        return;
      }

      var richBox = sender as RichTextBox;
      richBox?.SelectAll();
    }

    public static void ResetCombo(ComboBox combo)
    {
      if (combo == null) return;
      combo.Items.Clear();
      combo.Text = string.Empty;
    }

    public static void SetComboChoice(ComboBox combo, int choiceIndex)
    {
      if (combo == null) return;
      if (combo.Items.Count == 0) return;
      if (choiceIndex < 0) return;
      if (choiceIndex >= combo.Items.Count) return;

      combo.SelectedIndex = choiceIndex;
      combo.SelectedItem = combo.Items[choiceIndex];
      combo.Text = combo.SelectedItem.ToString();
    }

    public static string Spacer(int count = 1)
    {
      return count < 1 ? string.Empty : string.Empty.PadLeft(count);
    }
  }
}
